<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>Finalove-App-news</title>
		<link rel="stylesheet" href="../resource/font/css/font-awesome.min.css">
		<link rel="stylesheet" href="../resource/css/mint.css">
		<link rel="stylesheet" href="../resource/css/style.css">
		<script src="../resource/js/vue.js"></script>
		<script src="../resource/js/mint.min.js"></script>
		<script src="../resource/js/jquery.min.js"></script>
		<style type="text/css">
			.ct-box{
				margin-top:55%;
				width: 70%;
				margin-left: 15%;
			}
			.login-btn{
				margin-top:15px;
			}
			#main {
				background:url(../resource/img/not_login_box_bg.jpg) no-repeat center;
				background-size:100% 100%;  
			}
		</style>
	</head>
	<body>
		<div id="main">
			<mt-header fixed :title="title">
				<mt-button icon="back" slot="left" class="closeView"></mt-button>
			</mt-header>
			<div class="ct-box">
				<mt-field label="用户名" placeholder="请输入用户名/邮箱" v-model="form.user_name"></mt-field>
				<mt-field label="密码" placeholder="请输入密码" type="password" v-model="form.passwd"></mt-field>
				<mt-button class="login-btn" type="primary" size="large" @click="subForm">登陆</mt-button>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		var main = new Vue({
			el:"#main",
			data:{
				title:"登陆",
				form:{
					user_name:"",
					passwd:""
				},
				userInfo:{
					user_name:"",
					user_passwd:"",
				}
			},
			mounted:function() {
				this.init();
			},
			methods:{
				init() {
					// 获取配置
					$.getJSON('../resource/config.json',function(res){
						main.api_prefix = res.api_prefix;
						main.api_key = res.api_key;
						main.app_version = res.app_version;
						main.app_version_check_url = res.app_version_check_url;
					});
					// loading
					document.addEventListener('plusready',function () {
						// 沉浸header
						plus.navigator.setFullscreen(true);
						// header返回btn
						document.querySelector(".closeView").addEventListener('click',function(){
							plus.webview.currentWebview().close();
						});
						// backbutton事件修改
						plus.key.addEventListener('backbutton', function() {
							plus.webview.currentWebview().close();
							return false;
						}, false);
						// 获取参数
						main.userInfo = {
							user_name:plus.storage.getItem("user_name"),
							user_passwd:plus.storage.getItem("user_passwd")
						}
						main.form = {
							user_name:main.userInfo.user_name,
							passwd:main.userInfo.user_passwd
						};
					})
				},
				subForm() {
					if(this.form.user_name.length < 6 || this.form.user_name.length == ""){
						this.$toast({message:"用户名输入错误",position:"top",duration: 1000});
						return false;
					}
					if(this.form.passwd.length < 6 || this.form.passwd.length > 15){
						this.$toast({message:"用户名字符长度为6~15位",position:"top",duration: 1000});
						return false;
					}
					var url = this.api_prefix + "login/doLogin";
					var param = {
						api_key:this.api_key,
						params:{
							user_name:this.form.user_name,
							passwd:this.form.passwd
						}
					}
					$.post(url,param,function(res) {
						main.$toast({message:res.msg,position:"top",duration: 1000});
						if(res.code == 1){
							user_passwd:plus.storage.setItem("user_passwd",main.form.passwd);
							plus.storage.setItem("user_id",res.data.user_id);
							plus.storage.setItem("user_name",res.data.user_name);
							plus.storage.setItem("user_head",res.data.user_head);
							plus.runtime.restart();
						}
					});
				}
			}
		})
	</script>
</html>
